package com.homedo.async.mysql.support.prepare;

import com.homedo.async.common.dto.Pagination;
import com.homedo.async.mysql.support.dataobject.Example;
import com.homedo.async.mysql.support.dataobject.SqlInfo;
import com.homedo.plainly.logger.Logger;
import com.homedo.plainly.logger.LoggerFactory;

/**
 * @author jgshun
 * @date 2020/3/5 1:56 PM
 */
public abstract class Example2Sql {
    private static final Logger _LOGGER = LoggerFactory.getLogger(Example2Sql.class);

    public static Object[] prepare(Example example, Pagination pagination) {
        Object[] prepareSelectSql = new Object[2];
        
        if (pagination != null) {
            if (pagination.getOrders() != null && pagination.getOrders().size() > 0) {
                example.orderBy(pagination.getOrdersToStr());
            }
            example.param(pagination.getStart(), pagination.getSize());
            example.limit(" ? , ? ");
        }

        SqlInfo sqlInfo = example.end();

        prepareSelectSql[0] = sqlInfo.getSql();
        prepareSelectSql[1] = sqlInfo.getParams();

        return prepareSelectSql;
    }

}

